package com.fyzk.activity.lottery.jc.football.guoguan;

import com.fyzk.activity.lottery.jc.football.JCInfo;
import com.fyzk.utils.LotteryIDUtils;

import java.util.ArrayList;
import java.util.List;

public class JC_GuoGuanInfor {

    /**
     * n串n:  胜平负 ：最高8串n
     * 总进球 ：最高6串n
     * 比分、半全场 : 最高4串n
     */

    public static final int[][] n_n = {{3, 3}, {3, 4},//3串n
            {4, 4}, {4, 5}, {4, 6}, {4, 11},
            {5, 5}, {5, 6}, {5, 10}, {5, 16}, {5, 20}, {5, 26},
            {6, 6}, {6, 7}, {6, 15}, {6, 20}, {6, 22}, {6, 35}, {6, 42}, {6, 50}, {6, 57},
            {7, 7}, {7, 8}, {7, 21}, {7, 35}, {7, 120},
            {8, 8}, {8, 9}, {8, 28}, {8, 56}, {8, 70}, {8, 247}
    };


    private static final String RESULT_SPLIT = ",";

    /**
     * 获取过关方式编号
     *
     * @param guoGuans 过关方式名称（如：2串1,3串1）
     * @return 编号（如：2001,3001）
     */
    public static List<String> getChuanIds(String guoGuans, boolean isDanguan) {
        List<String> chuans = new ArrayList<String>();

        if (isDanguan) {
            chuans.add("1001");
        } else {
            if (guoGuans.contains(",")) {
                String[] str = guoGuans.split(",");
                for (int i = 0; i < str.length; i++) {
                    chuans.add(getChuanId(str[i]));
                }
            } else {
                chuans.add(getChuanId(guoGuans));
            }
        }

        return chuans;
    }

    /**
     * 获取过关方式编号
     *
     * @param guoGuan
     * @return
     */
    private static String getChuanId(String guoGuan) {
        String chuan = "error";
        if (guoGuan != null && guoGuan.contains("串")) {
            String[] str = guoGuan.split("串");

            switch (str[1].length()) {
                case 1:
                    chuan = str[0] + "00" + str[1];
                    break;
                case 2:
                    chuan = str[0] + "0" + str[1];
                    break;
                case 3:
                    chuan = str[0] + "" + str[1];
                    break;
                default:
                    break;
            }
        }

        return chuan;
    }

    /**
     * 获取比分编号
     *
     * @param bf_str 比分字串（如：1:2,3:4,胜其他）
     * @return
     */
    public static List<String> getBiFenIds(String bf_str) {
        List<String> biFens = new ArrayList<String>();

        if (bf_str.contains(RESULT_SPLIT)) {
            String[] str = bf_str.split(RESULT_SPLIT);
            for (int i = 0; i < str.length; i++) {
                biFens.add(getBiFenId(str[i]));
            }
        } else {
            biFens.add(getBiFenId(bf_str));
        }

        return biFens;
    }

    private static String getBiFenId(String bf) {
        String biFen = "";
        if (bf == null) {
            return biFen;
        }
        if (bf.contains(":")) {
            biFen = bf.split(":")[0] + bf.split(":")[1];
        } else if (bf.equals("胜其它")) {
            biFen = "90";
        } else if (bf.equals("平其它")) {
            biFen = "99";
        } else if (bf.equals("负其它")) {
            biFen = "09";
        }

        return biFen;
    }

//	/**
//	 * 获取总进球编号
//	 * @param zjq_str	总进球字串（如：1球,3球,7+球）
//	 * @return
//	 */
//	public static List<String> getZongJinQius(String zjq_str){
//		List<String> zjqs = new ArrayList<String>();
//
//		if (zjq_str.contains(RESULT_SPLIT)) {
//			String[] str = zjq_str.split(RESULT_SPLIT);
//			for (int i = 0; i < str.length; i++) {
//				zjqs.add(getZongJinQiuId(str[i]));
//			}
//		}else{
//			zjqs.add(getZongJinQiuId(zjq_str));
//		}
//
//		return zjqs;
//	}

    private static String getZongJinQiuId(String zjq) {
        String zongJinQiu = "";
        if (!zjq.contains("球")) {
            return zongJinQiu;
        }
        for (int i = 0; i < 8; i++) {
            if (zjq.contains(i + "")) {
                zongJinQiu = i + "";
                break;
            }
        }
        return zongJinQiu;
    }

    /**
     * 获取半全场编号
     *
     * @param bqc_str 半全场字串（如：胜胜,胜平,平负）
     * @return
     */
    public static List<String> getBanQuanChangs(String bqc_str) {
        List<String> bqcs = new ArrayList<String>();

        if (bqc_str.contains(RESULT_SPLIT)) {
            String[] str = bqc_str.split(RESULT_SPLIT);
            for (int i = 0; i < str.length; i++) {
                bqcs.add(getBanQuanChang(str[i]));
            }
        } else {
            bqcs.add(getBanQuanChang(bqc_str));
        }

        return bqcs;
    }

    private static String getBanQuanChang(String bqc) {
        String banQuanChan = "";
        String s = "胜";
        String p = "平";
        String f = "负";

        if (bqc.length() == 2 && (bqc.contains(s) || bqc.contains(p) || bqc.contains(f))) {
            if (bqc.contains(s)) {
                bqc = bqc.replace(s, "3");
            }
            if (bqc.contains(p)) {
                bqc = bqc.replace(p, "1");
            }
            if (bqc.contains(f)) {
                bqc = bqc.replace(f, "0");
            }

            banQuanChan = bqc;
        }

        return banQuanChan;
    }

    private static String getShengPingFu(String spf) {
        String result = "";
        if (spf.equals("胜")) {
            result = "3";
        } else if (spf.equals("平")) {
            result = "1";
        } else if (spf.equals("负")) {
            result = "0";
        }
        return result;
    }

    private static String getRangShengPingFu(String spf) {
        String result = "";
        if (spf.equals("让球胜")) {
            result = "3";
        } else if (spf.equals("让球平")) {
            result = "1";
        } else if (spf.equals("让球负")) {
            result = "0";
        }
        return result;
    }

    /**
     * 获取混合过关编号
     *
     * @param bqc_str 混合过关字串（如：胜,让球负,1:2,3:0,胜胜,平负。。。）
     * @return 如：*3010（3）*3006（0）*3007（12,30）*3009（33,10）
     */
    public static String getHunHes(String bqc_str, String teamId) {
        String result = "";

        String spf = "";
        String rspf = "";
        String bf = "";
        String bqc = "";
        String zjq = "";
        if (bqc_str.contains(RESULT_SPLIT)) {

            String[] str = bqc_str.split(RESULT_SPLIT);
            for (int i = 0; i < str.length; i++) {
                //....
                String s = getShengPingFu(str[i]);
                if (!s.equals("")) {
                    spf += s + ",";
                }
                String r = getRangShengPingFu(str[i]);
                if (!r.equals("")) {
                    rspf += r + ",";
                }
                String bf1 = getBiFenId(str[i]);
                if (!bf1.equals("")) {
                    bf += bf1 + ",";
                }
                String bqc1 = getBanQuanChang(str[i]);
                if (!bqc1.equals("")) {
                    bqc += bqc1 + ",";
                }
                String z = getZongJinQiuId(str[i]);
                if (!z.equals("")) {
                    zjq += z + ",";
                }
            }
        } else {
            String s = getShengPingFu(bqc_str);
            if (!s.equals("")) {
                spf += s + ",";
            }
            String r = getRangShengPingFu(bqc_str);
            if (!r.equals("")) {
                rspf += r + ",";
            }
            String bf1 = getBiFenId(bqc_str);
            if (!bf1.equals("")) {
                bf += bf1 + ",";
            }
            String bqc1 = getBanQuanChang(bqc_str);
            if (!bqc1.equals("")) {
                bqc += bqc1 + ",";
            }
            String z = getZongJinQiuId(bqc_str);
            if (!z.equals("")) {
                zjq += z + ",";
            }
        }

        if (!spf.equals("")) {
            spf = spf.substring(0, spf.length() - 1);

            spf = teamId + "*" + LotteryIDUtils.JZSPF_LOTTERY_ID_INT + "(" + spf + ")|";
        }
        if (!rspf.equals("")) {
            rspf = rspf.substring(0, rspf.length() - 1);

            rspf = teamId + "*" + LotteryIDUtils.JZRFSPF_LOTTERY_ID_INT + "(" + rspf + ")|";
        }
        if (!bf.equals("")) {
            bf = bf.substring(0, bf.length() - 1);

            bf = teamId + "*" + LotteryIDUtils.JZBF_LOTTERY_ID_INT + "(" + bf + ")|";
        }
        if (!bqc.equals("")) {
            bqc = bqc.substring(0, bqc.length() - 1);

            bqc = teamId + "*" + LotteryIDUtils.JZBQC_LOTTERY_ID_INT + "(" + bqc + ")|";
        }
        if (!zjq.equals("")) {
            zjq = zjq.substring(0, zjq.length() - 1);

            zjq = teamId + "*" + LotteryIDUtils.JZZJQ_LOTTERY_ID_INT + "(" + zjq + ")|";
        }

        result = spf + rspf + bf + bqc + zjq;

        if (!result.equals("")) {
            result = result.substring(0, result.length() - 1);
        }

        return result;
    }

    /**
     * 获取混合过关编号
     *
     * @return 如：*3010（3）*3006（0）*3007（12,30）*3009（33,10）
     */
    public static String getHunHes(JCInfo infor) {
        StringBuffer result = new StringBuffer();

        String teamId = infor.getMatchNum();

        StringBuffer spf = new StringBuffer();
        StringBuffer rspf = new StringBuffer();
        StringBuffer bf = new StringBuffer();
        StringBuffer bqc = new StringBuffer();
        StringBuffer zjq = new StringBuffer();


        String[] keyArray_spf = new String[]{infor.VS_3, infor.VS_1, infor.VS_0};
        String[] keyArray_rspf = new String[]{infor.LETVS_3, infor.LETVS_1, infor.LETVS_0};
        String[] keyArray_bf = new String[]{infor.BF_10, infor.BF_20, infor.BF_21,
                infor.BF_30, infor.BF_31, infor.BF_32,
                infor.BF_40, infor.BF_41, infor.BF_42,
                infor.BF_50, infor.BF_51, infor.BF_52,
                infor.BF_90, infor.BF_00, infor.BF_11,
                infor.BF_22, infor.BF_33, infor.BF_99,
                infor.BF_01, infor.BF_02, infor.BF_12, infor.BF_03,
                infor.BF_13, infor.BF_23, infor.BF_04,
                infor.BF_14, infor.BF_24, infor.BF_05,
                infor.BF_15, infor.BF_25, infor.BF_09};
        String[] keyArray_jqc = new String[]{infor.SCORE_0, infor.SCORE_1, infor.SCORE_2, infor
                .SCORE_3,
                infor.SCORE_4, infor.SCORE_5, infor.SCORE_6, infor.SCORE_7};
        String[] keyArray_bqc = new String[]{
                infor.BQC_33, infor.BQC_31, infor.BQC_30, infor.BQC_13,
                infor.BQC_11, infor.BQC_10, infor.BQC_03, infor.BQC_01,
                infor.BQC_00};

        for (String key : keyArray_spf) {
            JCInfo.SPInfo spInfo = infor.btnHGPojo.get(key);
            if (spInfo.isSel) {
                spf.append(spInfo.codeValue);
                spf.append(",");
            }
        }
        for (String key : keyArray_rspf) {
            JCInfo.SPInfo spInfo = infor.btnHGPojo.get(key);
            if (spInfo.isSel) {
                rspf.append(spInfo.codeValue);
                rspf.append(",");
            }
        }
        for (String key : keyArray_bf) {
            JCInfo.SPInfo spInfo = infor.btnHGPojo.get(key);
            if (spInfo.isSel) {
                bf.append(spInfo.codeValue);
                bf.append(",");
            }
        }
        for (String key : keyArray_jqc) {
            JCInfo.SPInfo spInfo = infor.btnHGPojo.get(key);
            if (spInfo.isSel) {
                zjq.append(spInfo.codeValue);
                zjq.append(",");
            }
        }
        for (String key : keyArray_bqc) {
            JCInfo.SPInfo spInfo = infor.btnHGPojo.get(key);
            if (spInfo.isSel) {
                bqc.append(spInfo.codeValue);
                bqc.append(",");
            }
        }

        if (spf.length() > 0) {
            spf = spf.deleteCharAt(spf.length() - 1);
            result.append(teamId);
            result.append("*");
            result.append(LotteryIDUtils.JZSPF_LOTTERY_ID_INT);
            result.append("(");
            result.append(spf);
            result.append(")|");
        }
        if (rspf.length() > 0) {
            rspf = rspf.deleteCharAt(rspf.length() - 1);
            result.append(teamId);
            result.append("*");
            result.append(LotteryIDUtils.JZRFSPF_LOTTERY_ID_INT);
            result.append("(");
            result.append(rspf);
            result.append(")|");
        }
        if (bf.length() > 0) {
            bf = bf.deleteCharAt(bf.length() - 1);
            result.append(teamId);
            result.append("*");
            result.append(LotteryIDUtils.JZBF_LOTTERY_ID_INT);
            result.append("(");
            result.append(bf);
            result.append(")|");
        }
        if (bqc.length() > 0) {
            bqc = bqc.deleteCharAt(bqc.length() - 1);
            result.append(teamId);
            result.append("*");
            result.append(LotteryIDUtils.JZBQC_LOTTERY_ID_INT);
            result.append("(");
            result.append(bqc);
            result.append(")|");
        }
        if (zjq.length() > 0) {
            zjq = zjq.deleteCharAt(zjq.length() - 1);
            result.append(teamId);
            result.append("*");
            result.append(LotteryIDUtils.JZZJQ_LOTTERY_ID_INT);
            result.append("(");
            result.append(zjq);
            result.append(")|");
        }
        if (!result.toString().equals("")) {
            result = result.deleteCharAt(result.length() - 1);
        }

        return result.toString();
    }

}
